﻿using Commons.Cache;
using Entity.Project;
using System.Collections.Generic;
using Commons;
using System;
using Senparc.WebSocket;
using System.Linq;
using Bussiness.Mangement.Project;
using System.ComponentModel.DataAnnotations;

namespace NetCoreAPI.Socket
{
    /// <summary>
    /// 游戏类型
    /// </summary>
    public enum GameType
    {
        /// <summary>
        /// 谁是卧底
        /// </summary>
        SSWD
    }

    //public class SocketHelp
    //{

    //    public static List<Room> Rooms = new List<Room>();
    //    /// <summary>
    //    /// 加载初始化房间
    //    /// </summary>
    //    public static void LoadRoom()
    //    {
    //        var cache = CacheService.GetCacheManager();
    //        string roomsCacheKay = "asfdouoansguosfiasfhas";
    //        if (cache.Exists(roomsCacheKay))
    //        {
    //            var strRooms = cache.GetValue(roomsCacheKay);
    //            Rooms = strRooms.JsonToModel<List<Room>>();
    //        }
    //        else
    //        {
    //            RoomLevel[] roomLevels = new RoomLevel[] { RoomLevel.One, RoomLevel.Two, RoomLevel.Three };
    //            int[,] littles = new int[3, 5] { { 5, 10, 25, 50, 100 }, { 100, 250, 500, 1000, 2000 }, { 2000, 5000, 10000, 20000, 50000 } };
    //            int[,] minJettons = new int[,] { { 1000, 2000, 3000, 5000, 10000 }, { 10000, 20000, 30000, 500000, 800000 }, { 800000, 1500000, 3000000, 5000000, 10000000 } };
    //            foreach (var roomLevel in roomLevels)
    //            {
    //                var findex = (int)roomLevel;
    //                for (int a = 0; a < 5; a++)
    //                {
    //                    for (int i = 0; i < 5; i++)
    //                    {
    //                        string key = Commons.Commonfs.RndCode(6, "", "").ToUpper();
    //                        while (Rooms.Exists(x => x.RoomKey == key))
    //                        {
    //                            key = Commons.Commonfs.RndCode(6, "", "").ToUpper();
    //                        }
    //                        Rooms.Add(new Room(key, "标准德扑", minJettons[findex, i], minJettons[findex, i] * 10, littles[findex, a] * 2, littles[findex, a], 9, roomLevel));
    //                    }
    //                }
    //            }
    //            cache.Set(roomsCacheKay, Rooms.ToJsonString(), TimeSpan.FromDays(30), TimeSpan.FromDays(30));
    //        }
    //    }

    //    /// <summary>
    //    /// 创建游戏记录
    //    /// </summary>
    //    /// <param name="key"></param>
    //    public static GameR CreateGame(string key)
    //    {
    //        var cache = CacheService.GetCacheManager();
    //        GameR gameR = new GameR() { Key = key, data = new Dictionary<string, List<ReceivedMessageData>>(), StartTime = DateTime.Now };
    //        cache.Set(key, gameR, TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30));
    //        return gameR;
    //    }
    //    public static GameR AddUserOperation(string key, string userToken, ReceivedMessageData data)
    //    {
    //        var cache = CacheService.GetCacheManager();
    //        GameR game = cache.Get<GameR>(key);
    //        if (game.data.ContainsKey(userToken))
    //        {
    //            game.data[userToken].Add(data);
    //        }
    //        else
    //        {
    //            game.data.Add(userToken, new List<ReceivedMessageData>() { data });
    //        }
    //        cache.Set(key, game, TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30));
    //        return game;
    //    }
    //    public static GameR EndGame(string key)
    //    {
    //        var cache = CacheService.GetCacheManager();
    //        cache.Remove(key);
    //        return null;
    //    }
    //}

    ///// <summary>
    ///// 房间通用方法
    ///// </summary>
    //public class RoomHelper
    //{

    //    private static Dictionary<string, object> lockObj = new Dictionary<string, object>();

    //    /// <summary>
    //    /// 进入下轮次 判断是否结束游戏 轮次是否首次
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    /// <param name="userToken"></param>
    //    public static void Next(int roomIndex, string userToken)
    //    {
    //        int turnNum = SocketHelp.Rooms[roomIndex].CurretnTurn;
    //        bool isEnd;
    //        GameNext(roomIndex, userToken, out isEnd);
    //        if (isEnd)
    //        {
    //            EndGame(roomIndex);
    //        }
    //        if (SocketHelp.Rooms[roomIndex].TurnFirst && turnNum == SocketHelp.Rooms[roomIndex].CurretnTurn)
    //        {
    //            SocketHelp.Rooms[roomIndex].TurnFirst = false;
    //        }
    //    }


    //    /// <summary>
    //    /// 开始游戏
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    /// <param name="room"></param>
    //    /// <param name="playBuss"></param>
    //    /// <param name="resultData"></param>
    //    public static void Start(int roomIndex, Room room, PlayingCardBussiness playBuss, ref ResultData resultData)
    //    {
    //        if (!lockObj.ContainsKey(room.RoomKey))
    //        {
    //            lockObj.Add(room.RoomKey, new object());
    //        }
    //        lock (lockObj[room.RoomKey])
    //        {
    //            //如果以开始游戏 则不执行
    //            if (SocketHelp.Rooms[roomIndex].IsStarting)
    //            {
    //                return;
    //            }
    //            SocketHelp.Rooms[roomIndex].IsStarting = true;
    //            resultData.Room = SocketHelp.Rooms[roomIndex];
    //            var connUsers = new List<RoomUser>();
    //            //判断人数是否达到两个
    //            if (SocketHelp.Rooms[roomIndex].Users.FindAll(x => x.IsConnection && x.IsDown && x.Jetton > SocketHelp.Rooms[roomIndex].Big).Count < 2)
    //            {
    //                SocketHelp.Rooms[roomIndex].IsStarting = false;
    //                return;
    //            }
    //            SocketHelp.Rooms[roomIndex].IsStarting = true;
    //            SocketHelp.Rooms[roomIndex].IsEnd = false;
    //            SocketHelp.Rooms[roomIndex].Records = null;
    //            SocketHelp.Rooms[roomIndex].GameAllJetton = 0;
    //            for (int i = 0; i < SocketHelp.Rooms[roomIndex].Users.Count; i++)
    //            {
    //                //坐下且没掉线
    //                if (SocketHelp.Rooms[roomIndex].Users[i].IsDown && SocketHelp.Rooms[roomIndex].Users[i].IsConnection)
    //                {
    //                    SocketHelp.Rooms[roomIndex].Users[i].IsStarting = true;
    //                }
    //                //收集掉线的人员
    //                //if (!SocketHelp.Rooms[roomIndex].Users[i].IsConnection)
    //                //{
    //                //    connUsers.Add(SocketHelp.Rooms[roomIndex].Users[i]);
    //                //}
    //            }
    //            //发牌
    //            GamePlayingCard gameCard = playBuss.AutoCrateDZPKGame(room.StartPlayer.Count);
    //            SocketHelp.Rooms[roomIndex].GameCard = gameCard;
    //            resultData.Game = SocketHelp.CreateGame(gameCard.Key);
    //            var userList = SocketHelp.Rooms[roomIndex].StartPlayer.ToList();
    //            #region 设置庄家
    //            //当前庄家
    //            int nowBankerNum = SocketHelp.Rooms[roomIndex].BankerNum;
    //            //获取下一位庄家的Number
    //            List<RoomUser> list = new List<RoomUser>();
    //            List<RoomUser> littleList = new List<RoomUser>();
    //            for (int i = 0; i < room.StartPlayer.Count; i++)
    //            {
    //                if (room.StartPlayer[i].Number < nowBankerNum)
    //                {
    //                    littleList.Add(room.StartPlayer[i]);
    //                }
    //                if (room.StartPlayer[i].Number > nowBankerNum)
    //                {
    //                    list.Add(room.StartPlayer[i]);
    //                }
    //            }
    //            list.AddRange(littleList);
    //            if (list == null || list.Count <= 0)
    //            {
    //                throw new Exception("系统错误!");
    //            }
    //            var nextBankerNum = list.First().Number;
    //            SocketHelp.Rooms[roomIndex].BankerNum = nextBankerNum;

    //            List<RoomUser> bankerList = new List<RoomUser>();
    //            List<RoomUser> bankerLittleList = new List<RoomUser>();
    //            for (int i = 0; i < room.StartPlayer.Count; i++)
    //            {
    //                if (room.StartPlayer[i].Number < nextBankerNum)
    //                {
    //                    bankerLittleList.Add(room.StartPlayer[i]);
    //                }
    //                if (room.StartPlayer[i].Number > nextBankerNum)
    //                {
    //                    bankerList.Add(room.StartPlayer[i]);
    //                }
    //            }
    //            bankerList.AddRange(bankerLittleList);
    //            #endregion
    //            for (int i = 0; i < userList.Count(); i++)
    //            {
    //                int userIndex = room.Users.FindIndex(x => x.UserToken == userList[i].UserToken);
    //                //如果玩家人数小于等于3 则将第一位
    //                if (userList.Count <= 3 && i == 0)
    //                {
    //                    //设置第一操作人
    //                    SocketHelp.Rooms[roomIndex].FirstUserToken = SocketHelp.Rooms[roomIndex].Users[userIndex].UserToken;
    //                    SocketHelp.Rooms[roomIndex].FirstUserId = SocketHelp.Rooms[roomIndex].Users[userIndex].UserId;
    //                    SocketHelp.Rooms[roomIndex].CurrentUserToken = userList[i].UserToken;
    //                    SocketHelp.Rooms[roomIndex].CurrentUserId = userList[i].UserId;
    //                    SocketHelp.Rooms[roomIndex].CurretnTurn = 1;
    //                }
    //                //赋予玩家手牌
    //                if (SocketHelp.Rooms[roomIndex].Users[userIndex].IsStarting)
    //                {
    //                    SocketHelp.Rooms[roomIndex].Users[userIndex].Cards = gameCard.PlayersCards[i];
    //                }
    //                //庄家后移
    //                //if (userList[i].Number == nextBankerNum && isBanker)
    //                //{
    //                //    SocketHelp.Rooms[roomIndex].BankerNum = userList[i].Number;
    //                //    isBanker = false;
    //                //}
    //                //自动大小盲注
    //                if (bankerList.Count >= 1 && bankerList[0].Number == userList[i].Number)
    //                {
    //                    SocketHelp.Rooms[roomIndex].Users[userIndex].UpJetton += room.Little;
    //                    SocketHelp.Rooms[roomIndex].Users[userIndex].Jetton -= room.Little;
    //                    SocketHelp.Rooms[roomIndex].GameAllJetton += room.Little;
    //                }
    //                else if (bankerList.Count >= 2 && bankerList[1].Number == userList[i].Number)
    //                {
    //                    SocketHelp.Rooms[roomIndex].Users[userIndex].UpJetton += room.Big;
    //                    SocketHelp.Rooms[roomIndex].Users[userIndex].Jetton -= room.Big;
    //                    SocketHelp.Rooms[roomIndex].GameAllJetton += room.Big;
    //                }
    //                else if (bankerList.Count >= 3 && bankerList[2].Number == userList[i].Number)
    //                {
    //                    //设置第一操作人 赋值接下来的操作人
    //                    SocketHelp.Rooms[roomIndex].FirstUserToken = SocketHelp.Rooms[roomIndex].Users[userIndex].UserToken;
    //                    SocketHelp.Rooms[roomIndex].FirstUserId = SocketHelp.Rooms[roomIndex].Users[userIndex].UserId;
    //                    SocketHelp.Rooms[roomIndex].CurrentUserToken = userList[i].UserToken;
    //                    SocketHelp.Rooms[roomIndex].CurrentUserId = userList[i].UserId;
    //                }
    //            }
    //            SocketHelp.Rooms[roomIndex].TurnFirst = true;
    //        }
    //    }

    //    /// <summary>
    //    /// 游戏结束
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    public static void EndGame(int roomIndex)
    //    {
    //        SocketHelp.Rooms[roomIndex].Messages.Clear();
    //        SocketHelp.Rooms[roomIndex].IsStarting = false;
    //        SocketHelp.Rooms[roomIndex].IsEnd = true;
    //        List<RoomUser> connUsers = new List<RoomUser>();
    //        //公布胜利人员 分配筹码
    //        #region 公布胜利人员 分配筹码
    //        var room = SocketHelp.Rooms[roomIndex];
    //        if (room.GameCard != null)
    //        {
    //            var pcB = PlayingCardBussiness.Init;
    //            var grB = GameRecordBussiness.Init;
    //            List<GameRecord> grList = new List<GameRecord>();
    //            DateTime dt = DateTime.Now;
    //            var cache = CacheService.GetCacheManager();
    //            var key = room.GameCard.Key;
    //            GameR game = cache.Get<GameR>(key);
    //            foreach (var item in SocketHelp.Rooms[roomIndex].StartPlayer)
    //            {
    //                GameRecord gr = new GameRecord();
    //                gr.StartTime = game.StartTime;
    //                gr.CommunityCards = room.GameCard.CommunityCards;
    //                gr.EndTime = dt;
    //                gr.IsWin = false;
    //                gr.Jetton -= item.UpJetton;
    //                gr.PlayerCards = item.Cards;
    //                gr.RecordKey = key;
    //                gr.RoomKey = room.RoomKey;
    //                gr.UserId = item.UserId;
    //                gr.isFold = item.IsFold;
    //                gr.Wands = pcB.GetOptimalWands(gr.CommunityCards, gr.PlayerCards);
    //                grList.Add(gr);
    //            }
    //            List<GameRecord> winlist = new List<GameRecord>();
    //            var jsgr = grList.FindAll(x => !x.isFold);//没有弃牌的才进行计算胜利
    //            winlist = pcB.GetWinWands(jsgr);
    //            double maxu = winlist.Sum(x => x.Jetton);//胜利玩家已上筹码总和 由于筹码情况是负数 所以取绝对值
    //            for (int i = 0; i < winlist.Count; i++)
    //            {
    //                var index = grList.FindIndex(x => x == winlist[i]);
    //                grList[index].IsWin = true;
    //                //0不能除 所以为0 直接等于0
    //                long jetton = grList[index].Jetton == 0 || room.GameAllJetton == 0 ? 0 : Convert.ToInt32(Math.Ceiling((grList[index].Jetton / maxu) * room.GameAllJetton));
    //                grList[index].Jetton = jetton;
    //                //找到玩家 并将筹码给他
    //                var userIndex = room.Users.FindIndex(x => x.UserId == winlist[i].UserId);
    //                SocketHelp.Rooms[roomIndex].Users[userIndex].Jetton += jetton;
    //            }

    //            //保存对战结局
    //            //记录对局
    //            string errorMessage;
    //            grB.AddRange(grList, out errorMessage);
    //            SocketHelp.Rooms[roomIndex].Records = grList.OrderByDescending(x => x.IsWin).ToList();
    //        }

    //        #endregion

    //        //游戏结束 修改玩家信息
    //        for (int i = 0; i < SocketHelp.Rooms[roomIndex].Users.Count; i++)
    //        {
    //            SocketHelp.Rooms[roomIndex].Users[i].IsFold = false;
    //            SocketHelp.Rooms[roomIndex].Users[i].UpJetton = 0;
    //            SocketHelp.Rooms[roomIndex].Users[i].IsStarting = false;
    //            SocketHelp.Rooms[roomIndex].Users[i].Cards = null;

    //            //收集掉线的人员
    //            if (!SocketHelp.Rooms[roomIndex].Users[i].IsConnection)
    //            {
    //                connUsers.Add(SocketHelp.Rooms[roomIndex].Users[i]);
    //            }
    //        }
    //        //清理掉线人员
    //        foreach (var item in connUsers)
    //        {
    //            int index = SocketHelp.Rooms[roomIndex].Users.FindIndex(x => x.UserToken == item.UserToken || x.UserId == item.UserId);
    //            SocketHelp.Rooms[roomIndex].Users.RemoveAt(index);
    //        }
    //        if (!string.IsNullOrWhiteSpace(SocketHelp.Rooms[roomIndex].GameCard.Key))
    //        {
    //            SocketHelp.EndGame(SocketHelp.Rooms[roomIndex].GameCard.Key);
    //        }
    //        SocketHelp.Rooms[roomIndex].GameCard = null;
    //        SocketHelp.Rooms[roomIndex].GameAllJetton = 0;
    //        SocketHelp.Rooms[roomIndex].CurrentUserId = 0;
    //        SocketHelp.Rooms[roomIndex].CurrentUserToken = string.Empty;
    //        SocketHelp.Rooms[roomIndex].FirstUserId = 0;
    //        SocketHelp.Rooms[roomIndex].FirstUserToken = string.Empty;
    //    }

    //    /// <summary>
    //    /// 切换当前操作人
    //    /// 判断当前轮次是否结束
    //    /// 以结束进入下一轮
    //    /// 轮次：1 公共卡牌无显示 2 显示三张 3四张 4五张
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    /// <param name="userToken"></param>
    //    /// <param name="isEnd">对局是否结束</param>
    //    public static void GameNext(int roomIndex, string userToken, out bool isEnd)
    //    {
    //        isEnd = false;
    //        //根据已上筹码、以及当前操作人来判断轮次是否+1 或者之后的玩家都allin
    //        var room = SocketHelp.Rooms[roomIndex];
    //        //没丢牌的玩家
    //        var player = room.StartPlayer.FindAll(x => !x.IsFold).OrderBy(x => x.Number).ToList();
    //        if (player.Count == 1)
    //        {
    //            isEnd = true;
    //            return;
    //        }
    //        //查看钱是否下得一样或者allin
    //        bool isEqual = true;//true：一轮全部齐
    //        long nowJetton = player.Max(x => x.UpJetton);
    //        for (int i = 1; i < player.Count; i++)
    //        {
    //            if (player[i].UpJetton == nowJetton || player[i].Jetton == 0)
    //            {
    //                isEqual = true;
    //            }
    //            else
    //            {
    //                isEqual = false; break;
    //            }
    //        }
    //        //进入下一轮次
    //        if ((room.FirstUserToken == userToken && !room.TurnFirst) || (!room.TurnFirst && isEqual))
    //        {
    //            //如果n-1个人都allin 直接结束
    //            var allinNum = player.FindAll(x => x.Jetton == 0).Count;
    //            if (allinNum + 1 == player.Count || allinNum == player.Count)
    //            {
    //                isEnd = true;
    //                SocketHelp.Rooms[roomIndex].CurretnTurn = 5;
    //                SocketHelp.Rooms[roomIndex].CurrentUserToken = SocketHelp.Rooms[roomIndex].FirstUserToken;
    //                SocketHelp.Rooms[roomIndex].CurrentUserId = SocketHelp.Rooms[roomIndex].FirstUserId;
    //            }
    //            else
    //            {
    //                //进入下一轮
    //                if (SocketHelp.Rooms[roomIndex].CurretnTurn == 4)
    //                {
    //                    isEnd = true;
    //                    SocketHelp.Rooms[roomIndex].CurrentUserToken = SocketHelp.Rooms[roomIndex].FirstUserToken;
    //                    SocketHelp.Rooms[roomIndex].CurrentUserId = SocketHelp.Rooms[roomIndex].FirstUserId;
    //                }
    //                SocketHelp.Rooms[roomIndex].CurretnTurn++;
    //                NextTurnCurrentUser(roomIndex);
    //                SocketHelp.Rooms[roomIndex].TurnFirst = true;
    //            }
    //        }
    //        else if (room.FirstUserToken != userToken || room.TurnFirst)
    //        {
    //            NextCurrentUser(roomIndex, out isEnd);
    //        }
    //    }

    //    /// <summary>
    //    /// 设置换轮次之后的当前操作人
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    public static void NextTurnCurrentUser(int roomIndex)
    //    {
    //        //查看第一操作人是否allin 或者已弃牌
    //        var room = SocketHelp.Rooms[roomIndex];
    //        var user = room.StartPlayer.Find(x => x.UserToken == room.FirstUserToken);
    //        if (user == null || user.IsFold || user.Jetton == 0)
    //        {
    //            //找到number大于他并且没有弃牌没有allin的人
    //            var u = room.StartPlayer.OrderBy(x => x.Number).ToList().Find(x => !x.IsFold && x.IsStarting && x.Jetton != 0);
    //            if (u != null)
    //            {
    //                SocketHelp.Rooms[roomIndex].CurrentUserToken = u.UserToken;
    //                SocketHelp.Rooms[roomIndex].CurrentUserId = u.UserId;
    //            }
    //            else
    //            {
    //                SocketHelp.Rooms[roomIndex].CurrentUserToken = SocketHelp.Rooms[roomIndex].FirstUserToken;
    //                SocketHelp.Rooms[roomIndex].CurrentUserId = SocketHelp.Rooms[roomIndex].FirstUserId;
    //            }
    //        }
    //        else
    //        {
    //            SocketHelp.Rooms[roomIndex].CurrentUserToken = SocketHelp.Rooms[roomIndex].FirstUserToken;
    //            SocketHelp.Rooms[roomIndex].CurrentUserId = SocketHelp.Rooms[roomIndex].FirstUserId;
    //        }

    //    }
    //    /// <summary>
    //    /// 操作人下一位
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    /// <param name="isEnd"></param>
    //    public static void NextCurrentUser(int roomIndex, out bool isEnd)
    //    {
    //        isEnd = false;
    //        var room = SocketHelp.Rooms[roomIndex];
    //        var user = room.StartPlayer.Find(x => x.UserToken == room.CurrentUserToken);
    //        if (user == null)
    //            return;
    //        List<RoomUser> list = new List<RoomUser>();
    //        List<RoomUser> littleList = new List<RoomUser>();
    //        for (int i = 0; i < room.StartPlayer.Count; i++)
    //        {
    //            if (room.StartPlayer[i].Number < user.Number)
    //            {
    //                littleList.Add(room.StartPlayer[i]);
    //            }
    //            else
    //            {
    //                list.Add(room.StartPlayer[i]);
    //            }
    //        }
    //        list.AddRange(littleList);
    //        //找到number大于他并且没有弃牌没有allin的人
    //        var u = list.Find(x => x.Jetton != 0 && !x.IsFold && x.Number != user.Number);
    //        if (u != null)
    //        {
    //            //如下一位处理掉线
    //            if (!u.IsConnection)
    //            {
    //                var userIndex = room.Users.FindIndex(x => x.UserToken == u.UserToken);
    //                if (userIndex >= 0)
    //                {
    //                    SocketHelp.Rooms[roomIndex].Users[userIndex].IsFold = true;
    //                }
    //                SocketHelp.Rooms[roomIndex].CurrentUserToken = u.UserToken;
    //                SocketHelp.Rooms[roomIndex].CurrentUserId = u.UserId;
    //                NextCurrentUser(roomIndex, out isEnd);
    //                return;
    //            }
    //            else
    //            {
    //                SocketHelp.Rooms[roomIndex].CurrentUserToken = u.UserToken;
    //                SocketHelp.Rooms[roomIndex].CurrentUserId = u.UserId;
    //            }
    //        }
    //        else
    //        {
    //            //操作轮次++
    //            SocketHelp.Rooms[roomIndex].CurretnTurn++;
    //            if (SocketHelp.Rooms[roomIndex].CurretnTurn == 5)
    //            {
    //                isEnd = true;
    //            }
    //            SocketHelp.Rooms[roomIndex].CurrentUserToken = SocketHelp.Rooms[roomIndex].FirstUserToken;
    //            SocketHelp.Rooms[roomIndex].CurrentUserId = SocketHelp.Rooms[roomIndex].FirstUserId;
    //        }
    //    }

    //    /// <summary>
    //    /// 判断是否正确的操作人
    //    /// </summary>
    //    /// <param name="roomIndex"></param>
    //    /// <param name="userToken"></param>
    //    /// <returns>true:正确</returns>
    //    public static bool IsCorrectOperation(int roomIndex, string userToken)
    //    {
    //        return SocketHelp.Rooms[roomIndex].CurrentUserToken == userToken && SocketHelp.Rooms[roomIndex].IsStarting;
    //    }

    //}


    public class ReceivedMessageData
    {
        /// <summary>
        /// 游戏类型
        /// </summary>
        public GameType gameType { get; set; }
        /// <summary>
        /// 操作
        /// </summary>
        public UserOperation Operation { get; set; }
        /// <summary>
        /// 消息内容 Json
        /// </summary>
        public string Message { get; set; }

        public string VisitTokenTo { get; set; }

        public DateTime DateTime { get; set; }

    }
    public class ResultData
    {
        public ResultData()
        {
            IsSuccess = false;
        }
        /// <summary>
        /// 返回的消息
        /// </summary>
        public string JsonData { get; set; }


        public string UserToken { get; set; }

        public bool IsSuccess { get; set; }
        public int Code { get; set; }
        public ReceivedMessageData ReceivedData { get; set; }
        /// <summary>
        /// 提示信息
        /// </summary>
        public string Message { get; set; }
    }

    ///// <summary>
    ///// 
    ///// </summary>
    //public class GameR
    //{
    //    public string Key { get; set; }
    //    public DateTime StartTime { get; set; }
    //    public DateTime EndTime { get; set; }
    //    /// <summary>
    //    /// 用户数据
    //    /// </summary>
    //    public Dictionary<string, List<ReceivedMessageData>> data { get; set; }
    //}

    ////房间用户类
    //public class RoomUser
    //{
    //    public string UserToken { get; set; }
    //    public string UserName { get; set; }
    //    public int UserId { get; set; }
    //    /// <summary>
    //    /// 头像
    //    /// </summary>
    //    public string Pictrue { get; set; }

    //    /// <summary>
    //    /// 当前筹码
    //    /// </summary>
    //    public long Jetton { get; set; }

    //    /// <summary>
    //    /// 以上筹码
    //    /// </summary>
    //    public long UpJetton { get; set; }
    //    /// <summary>
    //    /// 手牌
    //    /// </summary>
    //    public List<PlayingCard> Cards { get; set; }

    //    /// <summary>
    //    /// 是否坐下
    //    /// default：站起 false
    //    /// </summary>
    //    public bool IsDown { get; set; }

    //    /// <summary>
    //    /// 座位号
    //    /// </summary>
    //    public int Number { get; set; }
    //    /// <summary>
    //    /// 是否弃牌
    //    /// </summary>
    //    public bool IsFold { get; set; }
    //    /// <summary>
    //    /// socket连接id
    //    /// </summary>
    //    public string ConnectionId { get; set; }
    //    /// <summary>
    //    /// 是否连接
    //    /// </summary>
    //    public bool IsConnection { get; set; }
    //    /// <summary>
    //    /// 是否正在进行游戏
    //    /// </summary>
    //    public bool IsStarting { get; set; }
    //    ///// <summary>
    //    ///// 是否操作完
    //    ///// </summary>
    //    //public bool IsOperation { get; set; }
    //    //public List<PlayingCard> playingCards { get; set; }

    //    public RoomUser()
    //    {
    //        //playingCards = new List<PlayingCard>();
    //        IsDown = false;
    //        IsFold = false;
    //        IsStarting = false;
    //        //IsOperation = false;
    //    }

    //}

    ///// <summary>
    ///// 房间类
    ///// </summary>
    //public class Room
    //{
    //    [Key]
    //    public string RoomKey { get; set; }
    //    public string RoomName { get; set; }
    //    //用户集合
    //    public virtual List<RoomUser> Users { get; set; }
    //    /// <summary>
    //    /// 庄家
    //    /// </summary>
    //    public int BankerNum { get; set; }
    //    /// <summary>
    //    /// 最小携带筹码
    //    /// </summary>
    //    public int MinJetton { get; set; }
    //    /// <summary>
    //    /// 最大携带筹码
    //    /// </summary>
    //    public int MaxJetton { get; set; }
    //    /// <summary>
    //    /// 大盲注
    //    /// </summary>
    //    public int Big { get; set; }
    //    /// <summary>
    //    /// 小盲注
    //    /// </summary>
    //    public int Little { get; set; }
    //    /// <summary>
    //    /// 最大用户数量
    //    /// </summary>
    //    public int MaxUserNum { get; set; }
    //    public RoomLevel RoomLevel { get; set; }
    //    /// <summary>
    //    /// 是否正在进行游戏
    //    /// </summary>
    //    public bool IsStarting { get; set; }
    //    public bool IsEnd { get; set; }
    //    public GamePlayingCard GameCard { get; set; }
    //    /// <summary>
    //    /// 对局记录
    //    /// </summary>
    //    public List<GameRecord> Records { get; set; }
    //    /// <summary>
    //    /// 用户聊天记录
    //    /// </summary>
    //    public List<RoomMessage> Messages { get; set; }

    //    /// <summary>
    //    /// 上桌玩家
    //    /// </summary>
    //    /// <returns></returns>
    //    public List<RoomUser> Player => Users.FindAll(x => x.IsDown).OrderBy(x => x.Number).ToList();
    //    /// <summary>
    //    /// 正在玩的玩家
    //    /// </summary>
    //    /// <returns></returns>
    //    public List<RoomUser> StartPlayer => Users.FindAll(x => x.IsDown && x.IsStarting).OrderBy(x => x.Number).ToList();

    //    /// <summary>
    //    /// 底池
    //    /// </summary>
    //    public int GameAllJetton { get; set; }
    //    /// <summary>
    //    /// 当前操作人
    //    /// </summary>
    //    public string CurrentUserToken { get; set; }
    //    public int CurrentUserId { get; set; }
    //    /// <summary>
    //    /// 本轮第一位操作人
    //    /// </summary>
    //    public string FirstUserToken { get; set; }
    //    public int FirstUserId { get; set; }
    //    /// <summary>
    //    /// 当前轮次
    //    /// </summary>
    //    public int CurretnTurn { get; set; }
    //    /// <summary>
    //    /// 轮次是否刚开始
    //    /// </summary>
    //    public bool TurnFirst { get; set; }
    //    public Room()
    //    {
    //        Users = new List<RoomUser>();
    //        IsStarting = false; TurnFirst = false;
    //        Messages = new List<RoomMessage>();
    //    }
    //    public Room(string key, string name, int minJetton, int maxJetton, int big, int little, int maxUserNum, RoomLevel roomLevel)
    //    {
    //        TurnFirst = false;
    //        IsStarting = false;
    //        RoomName = name;
    //        RoomKey = key;
    //        MinJetton = minJetton;
    //        MaxJetton = maxJetton;
    //        Big = big;
    //        Little = little;
    //        MaxUserNum = maxUserNum;
    //        RoomLevel = roomLevel;
    //        Users = new List<RoomUser>();
    //        Messages = new List<RoomMessage>();
    //    }
    //}

    public class RoomMessage
    {
        public DateTime dateTime { get; set; }
        public string UserName { get; set; }
        public string Message { get; set; }
        public RoomMessage(string name, string message)
        {
            dateTime = DateTime.Now;
        }
    }

    ///// <summary>
    ///// 花色
    ///// </summary>
    //public class FlowerColor
    //{
    //    /// <summary>
    //    /// 名字
    //    /// </summary>
    //    [Key]
    //    public FlowerColorType Name { get; set; }
    //    /// <summary>
    //    /// 用于计算大小
    //    /// </summary>
    //    public int Value { get; set; }
    //}

    ///// <summary>
    ///// 牌面
    ///// </summary>
    //public class ReadingTheBoard
    //{
    //    /// <summary>
    //    /// 名字
    //    /// </summary>
    //    [Key]
    //    public string Name { get; set; }
    //    /// <summary>
    //    /// 用于计算大小
    //    /// </summary>
    //    public int Value { get; set; }
    //}


    ///// <summary>
    ///// 扑克牌
    ///// </summary>
    //public class PlayingCard
    //{
    //    public PlayingCard()
    //    {

    //    }
    //    /// <summary>
    //    /// 构造函数
    //    /// 自动生成名称、牌值和图片相对路径
    //    /// </summary>
    //    /// <param name="fc">花色</param>
    //    /// <param name="rb">牌面</param>
    //    public PlayingCard(FlowerColor fc, ReadingTheBoard rb)
    //    {
    //        EName = fc.Name.ToString() + rb.Name;
    //        Name = fc.Name.GetDisplayName() + rb.Name;
    //        Value = rb.Value * 10 + fc.Value;
    //        FlowerColor = fc;
    //        ReadingTheBoard = rb;
    //        PictrueSrc = $"/StaticFiles/PlayingCard/{EName}.png";
    //    }

    //    /// <summary>
    //    /// 英语名称
    //    /// </summary>
    //    [Key]
    //    public string EName { get; set; }
    //    /// <summary>
    //    /// 名称
    //    /// </summary>
    //    [Key]
    //    public string Name { get; set; }
    //    /// <summary>
    //    /// 花色
    //    /// </summary>
    //    public FlowerColor FlowerColor { get; set; }
    //    /// <summary>
    //    /// 牌面
    //    /// </summary>
    //    public ReadingTheBoard ReadingTheBoard { get; set; }
    //    /// <summary>
    //    /// 牌的大小
    //    /// </summary>
    //    public int Value { get; set; }
    //    /// <summary>
    //    /// 图片路径
    //    /// </summary>
    //    public string PictrueSrc { get; set; }
    //}

    ///// <summary>
    ///// 对局牌组
    ///// </summary>
    //public class GamePlayingCard
    //{
    //    /// <summary>
    //    /// 公共牌
    //    /// </summary>
    //    public List<PlayingCard> CommunityCards { get; set; }

    //    /// <summary>
    //    /// 各玩家牌
    //    /// </summary>
    //    public List<List<PlayingCard>> PlayersCards { get; set; }

    //    public string Key { get; set; }
    //}

    ///// <summary>
    ///// 牌组
    ///// </summary>
    //public class Wands
    //{
    //    /// <summary>
    //    /// 牌组
    //    /// </summary>
    //    public List<PlayingCard> Cards { get; set; }
    //    /// <summary>
    //    /// 牌等级
    //    /// </summary>
    //    public WandsLevel WandsLevel { get; set; }
    //    /// <summary>
    //    /// 牌名称
    //    /// </summary>
    //    public string WandsLevelName { get => WandsLevel.GetDisplayName(); }
    //    /// <summary>
    //    /// 最大牌花色
    //    /// </summary>
    //    public FlowerColor FlowerColor { get; set; }
    //    /// <summary>
    //    /// 最大等级的最大牌牌面
    //    /// </summary>
    //    public ReadingTheBoard ReadingTheBoard { get; set; }
    //    public Wands()
    //    {

    //    }
    //    public Wands(WandsLevel wandsLevel, FlowerColor flowerColor, ReadingTheBoard readingTheBoard)
    //    {
    //        Cards = new List<PlayingCard>();
    //        WandsLevel = wandsLevel;
    //        FlowerColor = flowerColor;
    //        ReadingTheBoard = readingTheBoard;
    //    }
    //    public Wands(WandsLevel wandsLevel, FlowerColor flowerColor, ReadingTheBoard readingTheBoard, List<PlayingCard> cards)
    //    {
    //        Cards = cards;
    //        WandsLevel = wandsLevel;
    //        FlowerColor = flowerColor;
    //        ReadingTheBoard = readingTheBoard;
    //    }

    //    public int LevelNum => (int)WandsLevel;
    //}

}
